f98e67
@@ -28,13 +28,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hive.common.JavaUtils;
 import org.apache.hadoop.hive.common.classification.InterfaceAudience;
 import org.apache.hadoop.hive.common.classification.InterfaceStability;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.api.MetaException;
-import org.apache.hadoop.hive.metastore.hooks.JDOConnectionURLHook;
-import org.apache.hadoop.util.ReflectionUtils;
 
 @InterfaceAudience.Private
 @InterfaceStability.Evolving
@@ -43,7 +40,7 @@
   private static final Log LOG = LogFactory.getLog(RetryingHMSHandler.class);
 
   private final IHMSHandler base;
-  private MetaStoreInit.MetaStoreInitData metaStoreInitData =
+  private final MetaStoreInit.MetaStoreInitData metaStoreInitData =
     new MetaStoreInit.MetaStoreInitData();
   private final HiveConf hiveConf;
 
@@ -112,13 +109,15 @@
public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
             // Due to reflection, the jdo exception is wrapped in
             // invocationTargetException
             caughtException = e.getCause();
-          }
-          else {
+          } else if (e.getCause() instanceof MetaException && e.getCause().getCause() != null
+              && e.getCause().getCause() instanceof javax.jdo.JDOException) {
+            // The JDOException may be wrapped further in a MetaException
+            caughtException = e.getCause().getCause();
+          } else {
             LOG.error(ExceptionUtils.getStackTrace(e.getCause()));
             throw e.getCause();
           }
-        }
-        else {
+        } else {
           LOG.error(ExceptionUtils.getStackTrace(e));
           throw e;
         }
@@ -127,8 +126,11 @@
public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
           // Due to reflection, the jdo exception is wrapped in
           // invocationTargetException
           caughtException = e.getCause();
-        }
-        else {
+        } else if (e.getCause() instanceof MetaException && e.getCause().getCause() != null
+            && e.getCause().getCause() instanceof javax.jdo.JDOException) {
+          // The JDOException may be wrapped further in a MetaException
+          caughtException = e.getCause().getCause();
+        } else {
           LOG.error(ExceptionUtils.getStackTrace(e.getCause()));
           throw e.getCause();
         }
